from impala.dbapi import connect

def create_conn(db_name):
    return connect(host='master', port=10000,database=db_name,auth_mechanism='NOSASL')

def show_db(conn, table_name):
    cursor = conn.cursor()
    results = cursor.execute("CREATE TABLE "+table_name+" ( eid int, name String, "
                    +" salary String, destignation String)"
                    +" COMMENT 'Employee details'"
                    +" ROW FORMAT DELIMITED"
                    +" FIELDS TERMINATED BY '\t'"
                    +" LINES TERMINATED BY '\n'"
                    +" STORED AS TEXTFILE")
    if results is None:
        print('创建表'+table_name+'成功，无返回值！')

if __name__ == '__main__':
    db_name = 'default'
    table_name = 'table1'
    conn = create_conn(db_name)
    show_db(conn,table_name)